package com.ohc.leetcode.链表;

public class 反转链表206 {

    public class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

    public static ListNode reverseList(ListNode head) {
        ListNode pre = null; // 前指针
        ListNode cur = head; // 当前指针
        ListNode temp = null;
        while (cur != null) {
            temp = head;
            cur.next = pre;
            pre = cur;  // 移动指针
            cur = cur.next; // 移动指针

        }

        return cur;
    }

    public static double Avg(int A[], int n) {
        if (n == 1)
            return A[0] / n;
        return (Avg(A, n - 1) * (n - 1) + A[n - 1]) / n;

    }



    public static void main(String[] args) {
        int[] arr = new int[]{1, 2, 3, 4, 5};
        double avg = Avg(arr, arr.length);
        System.out.println("avg = " + avg);
    }
}
